//
//  Array+MYSQLLiteTableiable.swift
//  DaRings
//
//  Created by 尹琼 on 2023/2/15.
//

import UIKit

public extension Array where Element == Int {
    
    mutating func removeBothEndZero() ->[Element] {
        
        if isEmpty {
            return self
        }
        
        var before: Int = 0
        var removeBeforeI: Int?
        var removeAfterI: Int?
        
        for (i, e) in self.enumerated() {
            
            if before == 0 && e > 0 {
                removeBeforeI = i
               break
            }
            before = e
        }
        
        
        if let removeBeforeI = removeBeforeI {
            self.removeSubrange( 0 ..< removeBeforeI)
        }
        
    
        before = 0
        for (i, e) in self.reversed().enumerated() {
            if before == 0 && e > 0 {
                removeAfterI = self.count - i
               break
            }
            before = e
        }
        
        if let removeAfterI = removeAfterI {
            self.removeSubrange(removeAfterI ..< self.count)
        }
       
        return self
        
    }
}
